Remove WiFi Connection
Description
The remove_wifi_connection
function deletes a Wi-Fi connection using the provided SSID.
Function Signature:
def remove_wifi_connection(ssid: str) -> None:
Parameters
- ssid (str): The SSID (name) of the Wi-Fi connection to be removed.
Returns
- None
Example Usage
Here’s an example of how the function works:
remove_wifi_connection('HomeNetwork')
Example Output:
Removed existing connection: HomeNetwork
Code
import subprocess
def remove_wifi_connection(ssid: str) -> None:
try:
subprocess.run(['sudo', 'nmcli', 'connection', 'delete', ssid], check=True)
print(f"Removed existing connection: {ssid}")
except subprocess.CalledProcessError as ex:
print(f"Failed to remove connection: {ssid}. It might not exist.")
Errors and Exceptions
- This function uses
subprocess.run()
to execute thenmcli
command. If the Wi-Fi connection is not found, or if there's an issue with permissions, asubprocess.CalledProcessError
will be raised.